/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

package com.gitee.minimalismstyle.fresh.flowable.api.feign

import org.springframework.web.bind.annotation.*
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.flowable.api.annotation.FlowableClient
import com.gitee.minimalismstyle.fresh.flowable.api.config.FlowableFeignConfig
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.*
import org.springframework.http.MediaType
import org.springframework.web.multipart.MultipartFile

/**
 * Users
 * @author maoxiaodong
 */
@FlowableClient(configuration = [FlowableFeignConfig::class])
interface UsersApi {


    /**
     * List users
     */
    @GetMapping("/identity/users")
    fun listUsers(
        @RequestParam(name = "id", required = false) id: String?,
        @RequestParam(name = "firstName", required = false) firstName: String?,
        @RequestParam(name = "lastName", required = false) lastName: String?,
        @RequestParam(name = "displayName", required = false) displayName: String?,
        @RequestParam(name = "email", required = false) email: String?,
        @RequestParam(name = "firstNameLike", required = false) firstNameLike: String?,
        @RequestParam(name = "lastNameLike", required = false) lastNameLike: String?,
        @RequestParam(name = "displayNameLike", required = false) displayNameLike: String?,
        @RequestParam(name = "emailLike", required = false) emailLike: String?,
        @RequestParam(name = "memberOfGroup", required = false) memberOfGroup: String?,
        @RequestParam(name = "tenantId", required = false) tenantId: String?,
        @RequestParam(name = "potentialStarter", required = false) potentialStarter: String?,
        @RequestParam(name = "sort", required = false) sort: String?
    ): R<DataResponse<UserResponse>>

    /**
     * Create a user
     */
    @PostMapping("/identity/users")
    fun createUser(
        @RequestBody(required = false) body: UserRequest?
    ): R<UserResponse>

    /**
     * Get a single user
     */
    @GetMapping("/identity/users/{userId}")
    fun getUser(
        @PathVariable("userId") userId: String
    ): R<UserResponse>

    /**
     * All request values are optional. For example, you can only include the firstName attribute in the request body JSON-object, only updating the firstName of the user, leaving all other fields unaffected. When an attribute is explicitly included and is set to null, the user-value will be updated to null. Example: {"firstName" : null} will clear the firstName of the user).
     */
    @PutMapping("/identity/users/{userId}")
    fun updateUser(
        @PathVariable("userId") userId: String,
        @RequestBody(required = false) body: UserRequest?
    ): R<UserResponse>

    /**
     * Delete a user
     */
    @DeleteMapping("/identity/users/{userId}")
    fun deleteUser(
        @PathVariable("userId") userId: String
    ): R<Any>

    /**
     * List user’s info
     */
    @GetMapping("/identity/users/{userId}/info")
    fun listUserInfo(
        @PathVariable("userId") userId: String
    ): R<Any>

    /**
     * Create a new user’s info entry
     */
    @PostMapping("/identity/users/{userId}/info")
    fun createUserInfo(
        @PathVariable("userId") userId: String,
        @RequestBody(required = false) body: UserInfoRequest?
    ): R<UserInfoResponse>

    /**
     * Get a user’s info
     */
    @GetMapping("/identity/users/{userId}/info/{key}")
    fun getUserInfo(
        @PathVariable("userId") userId: String,
        @PathVariable("key") key: String
    ): R<UserInfoResponse>

    /**
     * Update a user’s info
     */
    @PutMapping("/identity/users/{userId}/info/{key}")
    fun updateUserInfo(
        @PathVariable("userId") userId: String,
        @PathVariable("key") key: String,
        @RequestBody(required = false) body: UserInfoRequest?
    ): R<UserInfoResponse>

    /**
     * Delete a user’s info
     */
    @DeleteMapping("/identity/users/{userId}/info/{key}")
    fun deleteUserInfo(
        @PathVariable("userId") userId: String,
        @PathVariable("key") key: String
    ): R<Any>

    /**
     * The response body contains the raw picture data, representing the user’s picture. The Content-type of the response corresponds to the mimeType that was set when creating the picture.
     */
    @GetMapping("/identity/users/{userId}/picture")
    fun getUserPicture(
        @PathVariable("userId") userId: String
    ): R<Any>

    /**
     * The request should be of type multipart/form-data. There should be a single file-part included with the binary value of the picture. On top of that, the following additional form-fields can be present:

    mimeType: Optional mime-type for the uploaded picture. If omitted, the default of image/jpeg is used as a mime-type for the picture.
     */
    @PutMapping(value=["/identity/users/{userId}/picture"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
    fun updateUserPicture(
        @PathVariable("userId") userId: String,
        @RequestParam(name = "file", required = true) file: MultipartFile
    ): R<Any>
}